package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.common.query.DestinationQuery;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/destination")
public class DestinationController {

    @Reference
    private IDestinationService destinationService;

    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") DestinationQuery qo, Model model) {
        PageInfo pageInfo = destinationService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        if (qo.getParentId() != null) {
            List<Destination> toast = destinationService.toasts(qo.getParentId());
            model.addAttribute("toasts", toast);
        }
        return "destination/list";
    }

    @RequestMapping("/changeHotState")
    @ResponseBody
    public Object changeHotState(Long id) {
        return destinationService.changeHotState(id);
    }
}
